package com.dou.sample.opengl_project.utls;

import android.content.Context;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * Created by Dou on 2018/1/15.
 */

public class TextResourceReader {
    public static String readTextFileFromResource(Context context, int resId) {
        StringBuilder sb = new StringBuilder();

        try {

            InputStream inputStream = context.getResources().openRawResource(resId);
            InputStreamReader isr = new InputStreamReader(inputStream);
            BufferedReader bufferedReader = new BufferedReader(isr);

            String nextLine;

            while ((nextLine = bufferedReader.readLine()) != null) {
                sb.append(nextLine);
                sb.append("\n");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return sb.toString().trim();
    }
}
